<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script type="text/javascript">
      /* 
        理解闭包,是内部函数,主要作用是能拿到函数内部的私有变量,平常方式是拿不到的
      */
      function test() {
        var a = 100;
        return function test2() {
          return a;
        };
      }

      var c = test();
      var d = c();
      console.log(d);

      //用完需要回收资源
      c = null;
      d = null;
      //能不用就不用
    </script>
  </body>
</html>
